import Mock from 'mockjs'
const mockFiles = require.context('./modules', false, /\.js$/);
let mocks = [];
mockFiles.keys().forEach(key => {

    console.log(key);
    // debugger;
    let tmp = mockFiles(key);
    if(tmp.length){
        for(var i=0;i<tmp.length;i++){
            if(typeof tmp[i] === "function"){
                mocks.push(tmp[i]());
            }else{
                mocks.push(tmp[i]);
            }
        }
    }
    if(tmp.default.length){
        for(var i=0;i<tmp.default.length;i++){
            if(typeof tmp.default[i] === "function"){
                mocks.push(tmp.default[i]());
            }else{
                mocks.push(tmp.default[i]);
            }
        }
    }

    // debugger;
    // mocks.push(...mockFiles(key))
})

mocks.forEach(item => {
    if(typeof  item.response === "function"){
        Mock.mock(process.env.VUE_APP_BASE_API + item.url, item.method, ops=>item.response(ops))
    }else{
        Mock.mock(process.env.VUE_APP_BASE_API + item.url, item.method, item.response)

    }
    // debugger;
})

// let apis = {};

// mockFiles.keys().forEach(key => {
//     // 获取文件名，将 ./ 和 .js 替换为空， 最终格式  common
//     const fileName = key.replace(/(\.\/|\.js)/g, '');
//     // 填充数据
//     apis[fileName] = mockFiles(key);
// })

// debugger;

export default Mock